# 我在这个python文件中书写的全部都是能够很方便的操作数据库的方法
import pandas as pd
import pymysql
def get_sql_connection():
    db_info = {
        "host":"192.168.1.116",
        "user":"root",
        "password":"123",
        "database":"mydb2",
        "charset":"utf8"
    }
    conn = pymysql.connect(**db_info)
    return conn

def get_mysql_case_data(interface_type):
    conn = get_sql_connection()
    sql = "select * from mumu where interface_type = '{}'".format(interface_type)
    cursor = conn.cursor()
    cursor.execute(sql)
    result = cursor.fetchall()
    return result


def get_mysql_case_data_for_pandas(interface_type):
    conn = get_sql_connection()
    sql = "select * from mumu where interface_type = '{}'".format(interface_type)
    interface_type_data = pd.read_sql(sql, conn)
    # 解析数据
    final_data = []
    # print(interface_type_data)
    for i in interface_type_data.index:
        inner_data = {}
        for d in interface_type_data.iloc[[i]]:
            inner_data[d] = interface_type_data[d][i]
        final_data.append(inner_data)
    # return interface_type_data
    return final_data
